using System;
using System.Collections.Generic;
using System.Text;
using Calc.Execution;

namespace Calc.Operations
{
	public abstract class BinaryOperator : IOperator
	{
		protected IOperand _leftSide = null;
		protected IOperand _rightSide = null;

		protected double _value;

		public BinaryOperator() : this (null, null)
		{
			_value = double.MinValue;
		}

		public BinaryOperator(IOperand leftSide, IOperand rightSide)
		{
			_leftSide = leftSide;
			_rightSide = rightSide;
		}

		public IOperand LeftSide
		{
			get { return _leftSide; }
			set { _leftSide = value; }
		}

		public IOperand RightSide
		{
			get { return _rightSide; }
			set { _rightSide = value; }
		}

		public abstract CalcResult Calc(ExecutionContext context);

		public abstract int Precidence { get; }

		public abstract string Symbol { get; }

		public virtual double GetValue(ExecutionContext context)
		{
			if ( _value == double.MinValue )
				Calc(context);

			return _value;
		}


		public override string ToString()
		{
			string left = "";
			if ( _leftSide != null )
				left = _leftSide.ToString();

			string right = "";

			if ( _rightSide != null )
				right = _rightSide.ToString();

			return left + Symbol + right;
		}

	}
}
